package com.chenfan.privilege.client;

import com.chenfan.ccp.common.result.R;
import com.chenfan.privilege.dto.UserDTO;
import com.chenfan.privilege.vo.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author K
 * @date 2021/1/29
 *
 */

@FeignClient(value = "chenfan-cloud-privilege", url = "${feign.privilege:}")
public interface PrivilegeClient {

    /**
     * 获取指定用户所在部门负责人
     *
     * @param user
     *            {@link UserDTO}
     * @return {@link DepartmentHeadVO}
     */
    @PostMapping(value = "/department/getDepartmentHead", produces = "application/json;charset=utf-8")
    Response<DepartmentHeadVO> getDepartmentHead(@RequestBody UserDTO user);

    default DepartmentVO getDepartmentHeadByUserId(Long userId) {
        Map<Long, DepartmentVO> map = getDepartmentHeadByUserIds(Collections.singletonList(userId)).getObj();
        return map.get(userId);
    }

    @PostMapping(value = "/department/getDepartmentHeadByUserIds", produces = "application/json;charset=utf-8")
    Response<Map<Long, DepartmentVO>> getDepartmentHeadByUserIds(List<Long> userId);

    /**
     * 获取全部用户
     *
     * @param
     * @return
     */
    @ApiOperation(value = "获取全部租户", notes = "获取全部租户")
    @GetMapping(value = "tenant/getAllTenantList")
    R<List<STenantRes>> getAllTenantList();

    /**
     * 获取用户信息
     *
     * @param userId 用户id
     * @return 用户信息
     */
    @GetMapping(value = "/users/getUserById")
    Response<SUserVO> getUserById(@RequestParam Long userId);
}
